package org.light.utils;

import java.util.List;

import org.light.domain.Domain;
import org.light.domain.Dropdown;
import org.light.domain.Field;
import org.light.domain.ManyToManyCandidate;
import org.light.domain.Project;

public class ProjectDecorateUtil {
	public static void decorateJavaFieldToRust(Field field){
		if ("Integer".equals(field.getFieldType())||"int".equals(field.getFieldType())) field.setFieldType("i32"); 
		if ("Long".equals(field.getFieldType())||"long".equals(field.getFieldType())) field.setFieldType("i64");
		if ("Float".equals(field.getFieldType())||"float".equals(field.getFieldType())) field.setFieldType("f32");	
		if ("Double".equals(field.getFieldType())||"double".equals(field.getFieldType())) field.setFieldType("f64");	
		if ("Boolean".equals(field.getFieldType())||"boolean".equals(field.getFieldType())) field.setFieldType("bool");		
	}
	
	public static void decorateJavaFieldToGolang(Field field){
		if ("Integer".equals(field.getFieldType())||"int".equals(field.getFieldType())) field.setFieldType("int32"); 
		if ("Long".equals(field.getFieldType())||"long".equals(field.getFieldType())) field.setFieldType("int64");
		if ("Float".equals(field.getFieldType())||"float".equals(field.getFieldType())) field.setFieldType("float32");	
		if ("Double".equals(field.getFieldType())||"double".equals(field.getFieldType())) field.setFieldType("float64");	
		if ("Boolean".equals(field.getFieldType())||"boolean".equals(field.getFieldType())) field.setFieldType("bool");	
		if ("String".equals(field.getFieldType())) field.setFieldType("string");	
	}
	
	public static void decorateRustFieldToJava(Field field){
		if ("i32".equals(field.getFieldType())) field.setFieldType("Integer"); 
		if ("i64".equals(field.getFieldType())) field.setFieldType("Long");
		if ("f32".equals(field.getFieldType())) field.setFieldType("Float");	
		if ("f64".equals(field.getFieldType())) field.setFieldType("Double");	
		if ("bool".equals(field.getFieldType())) field.setFieldType("Boolean");		
	}
	
	public static void decorateJavaDomainToRust(Domain domain){
		for (Field f: domain.getFields()) {
			if (! (f instanceof Dropdown)) {
				decorateJavaFieldToRust(f);
			}
		}		
	}
	
	public static void decorateJavaDomainToGolang(Domain domain){
		for (Field f: domain.getFields()) {
			if (! (f instanceof Dropdown)) {
				decorateJavaFieldToGolang(f);
			}
		}		
	}
	
	public static void decorateRustDomainToJava(Domain domain){
		for (Field f: domain.getFields()) {
			if (! (f instanceof Dropdown)) {
				decorateRustFieldToJava(f);
			}
		}		
	}

	public static void decorateRustFieldToGolang(Field field){
		if ("i32".equals(field.getFieldType())) field.setFieldType("int32"); 
		if ("i64".equals(field.getFieldType())) field.setFieldType("int64");
		if ("f32".equals(field.getFieldType())) field.setFieldType("float32");	
		if ("f64".equals(field.getFieldType())) field.setFieldType("float64");	
		if ("String".equals(field.getFieldType())) field.setFieldType("string");		
	}
	
	public static void decorateRustDomainToGolang(Domain domain){
		for (Field f: domain.getFields()) {
			if (! (f instanceof Dropdown)) {
				decorateRustFieldToGolang(f);
			}
		}		
	}
	
	public static void decorateJavaMtmCandidateToRust(ManyToManyCandidate mtmc){
		if (mtmc.getMaster() != null) decorateJavaDomainToRust(mtmc.getMaster());
		if (mtmc.getSlave() != null) decorateJavaDomainToRust(mtmc.getSlave());
		if (mtmc.getMasterId() != null) decorateJavaFieldToRust(mtmc.getMasterId());
		if (mtmc.getSlaveId() != null) decorateJavaFieldToRust(mtmc.getSlaveId());		
	}
	
	public static void decorateJavaMtmCandidateToGolang(ManyToManyCandidate mtmc){
		if (mtmc.getMaster() != null) decorateJavaDomainToGolang(mtmc.getMaster());
		if (mtmc.getSlave() != null) decorateJavaDomainToGolang(mtmc.getSlave());
		if (mtmc.getMasterId() != null) decorateJavaFieldToGolang(mtmc.getMasterId());
		if (mtmc.getSlaveId() != null) decorateJavaFieldToGolang(mtmc.getSlaveId());		
	}
	
	public static void decorateRustMtmCandidateToJava(ManyToManyCandidate mtmc){
		if (mtmc.getMaster() != null) decorateRustDomainToJava(mtmc.getMaster());
		if (mtmc.getSlave() != null) decorateRustDomainToJava(mtmc.getSlave());
		if (mtmc.getMasterId() != null) decorateRustFieldToJava(mtmc.getMasterId());
		if (mtmc.getSlaveId() != null) decorateRustFieldToJava(mtmc.getSlaveId());		
	}

	public static void decorateRustMtmCandidateToGolang(ManyToManyCandidate mtmc){
		if (mtmc.getMaster() != null) decorateRustDomainToGolang(mtmc.getMaster());
		if (mtmc.getSlave() != null) decorateRustDomainToGolang(mtmc.getSlave());
		if (mtmc.getMasterId() != null) decorateRustFieldToGolang(mtmc.getMasterId());
		if (mtmc.getSlaveId() != null) decorateRustFieldToGolang(mtmc.getSlaveId());		
	}
	
	public static Project decorateJavaProjectToTower(Project project){
		for (Domain d: project.getDomains()) {
			decorateJavaDomainToRust(d);
		}
		for(List<Domain> dds: project.getDataDomains()){
			for (Domain dd: dds) {
				decorateJavaDomainToRust(dd);
			}
		}
		for (ManyToManyCandidate mtmc:project.getMtmCandidates()){
			decorateJavaMtmCandidateToRust(mtmc);
		}
		for (List<ManyToManyCandidate> vmtmcs :project.getMtmCandidatesValues()) {
			for (ManyToManyCandidate vmtmc:vmtmcs){
				decorateJavaMtmCandidateToRust(vmtmc);
			}
		}
		return project;
	}
	
	public static Project decorateJavaProjectToSimple(Project project){
		for (Domain d: project.getDomains()) {
			decorateJavaDomainToGolang(d);
		}
		for(List<Domain> dds: project.getDataDomains()){
			for (Domain dd: dds) {
				decorateJavaDomainToGolang(dd);
			}
		}
		for (ManyToManyCandidate mtmc:project.getMtmCandidates()){
			decorateJavaMtmCandidateToGolang(mtmc);
		}
		for (List<ManyToManyCandidate> vmtmcs :project.getMtmCandidatesValues()) {
			for (ManyToManyCandidate vmtmc:vmtmcs){
				decorateJavaMtmCandidateToGolang(vmtmc);
			}
		}
		return project;
	}
	
	public static Project decorateRustProjectToJEEEU(Project project){
		for (Domain d: project.getDomains()) {
			decorateRustDomainToJava(d);
		}
		for(List<Domain> dds: project.getDataDomains()){
			for (Domain dd: dds) {
				decorateRustDomainToJava(dd);
			}
		}
		for (ManyToManyCandidate mtmc:project.getMtmCandidates()){
			decorateRustMtmCandidateToJava(mtmc);
		}
		for (List<ManyToManyCandidate> vmtmcs :project.getMtmCandidatesValues()) {
			for (ManyToManyCandidate vmtmc:vmtmcs){
				decorateRustMtmCandidateToJava(vmtmc);
			}
		}
		return project;
	}

    public static Project decorateRustProjectToSimple(Project project) {
		for (Domain d: project.getDomains()) {
			decorateRustDomainToGolang(d);
		}
		for(List<Domain> dds: project.getDataDomains()){
			for (Domain dd: dds) {
				decorateRustDomainToGolang(dd);
			}
		}
		for (ManyToManyCandidate mtmc:project.getMtmCandidates()){
			decorateRustMtmCandidateToGolang(mtmc);
		}
		for (List<ManyToManyCandidate> vmtmcs :project.getMtmCandidatesValues()) {
			for (ManyToManyCandidate vmtmc:vmtmcs){
				decorateRustMtmCandidateToGolang(vmtmc);
			}
		}
		return project;
	}
}
